package com.elegantsoft.pakistannews;

import java.util.ArrayList;
import java.util.Arrays;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.atiffarrukh.pakistannews.R;
import com.google.analytics.tracking.android.EasyTracker;

public class AlternateStart extends SherlockActivity {
	private boolean english;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		
		Bundle b = getIntent().getExtras();
		
		ListView lv = (ListView) findViewById(R.id.catList);
		english = b.getBoolean("english");
		if(b.getBoolean("english")){
			String[] channels = { "Geo", "PTV News", "Aaj News",
					"Express Tribune",  "The News", "Buisness Recorder",
					"BBC", "Popular Science", "Pro Pakistani" };
			ArrayList<String> channelsList = new ArrayList<String>();
			channelsList.addAll(Arrays.asList(channels));
	
			MyCustommAdapter adapter = new MyCustommAdapter(this, channels);
			lv.setAdapter(adapter);
		}else {
			String[] channels = { "Waqt","Nawai Waqt Urdu", "Jang News Urdu"};
			ArrayList<String> channelsList = new ArrayList<String>();
			channelsList.addAll(Arrays.asList(channels));
	
			MyCustommAdapter adapter = new MyCustommAdapter(this, channels);
			lv.setAdapter(adapter);
		
		}
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				TextView tv = (TextView) view.findViewById(R.id.text1);
				String channel = tv.getText().toString();
				Intent i = new Intent(getApplicationContext(),
						com.elegantsoft.pakistannews.AlternateSend.class);
				i.putExtra("channelName", channel);
				i.putExtra("english", english);
				startActivity(i);
			}
		});
	}
	
	   @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	       MenuInflater inflater = getSupportMenuInflater();
	       inflater.inflate(R.menu.main, menu);
	       return super.onCreateOptionsMenu(menu);
	    }
	   
	   @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.action_settings:
			Intent i = new Intent(getApplicationContext(), Preferences.class);
			startActivity(i);
			break;
		 case android.R.id.home:
	         // Do whatever you want, e.g. finish()
	    	Intent in = new Intent(getApplicationContext(), EnglishUrduChoice.class);
	    	in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	//i.putExtra("category",english );
	    	startActivity(in);
	    	finish();
	        return true;
		default:
			break;
		}
		return true;
	}

		 @Override
		  public void onStart() {
		    super.onStart();
		  
		    //EasyTracker.getInstance().activityStart(this); // Google Analytics.
		  }

		  @Override
		  public void onStop() {
		    super.onStop();
		    
		    //EasyTracker.getInstance().activityStop(this); // Google Analytics.
		  }

}
